home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4390 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using MFC with C
  5. Date: 30 Jan 1996 03:15:29 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4ek2gh$t26@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 29, 1996 19:31:35 in article <Using MFC with C>, 'sean@crl.com (Sean
  15. Kenefick)' wrote: 
  16.  
  17.  
  18. >I'm a C programmer just now learning C++. 
  19. >I have an exisiting project -- a big one -- that has been written in 
  20. >C.  I want to add a new C++ module with a newly created class which 
  21. >uses, but isn't derived from, a couple of MFC classes (CString for 
  22. >example).  I *definitely* don't want to rewrite all my C code.  Is it 
  23. >possible to call a class' method in a C++ module from an exisiting 
  24. >external C module?  How should they be declared?  I tried using extern 
  25. >and extern "C" but the compiler just threw it back at me. 
  26. >BTW:  I can't put all these things in the same module because "AFX.H" 
  27. >and "WINDOWS.H" conflict with each other.  The C code won't compile 
  28. >with the "AFX.H" and vice-versa. 
  29. >Any help would be greatly appreciated. 
  30. There's no (reasonable) way to call C++ class member functions  
  31. directly from C.  You need to write an API layer for the C++ module. 
  32. If you're passing pointers to C++ classes to the C side, then you can 
  33. do something like this: 
  34.  
  35. int FooApi (void * object, int arg) 
  36.  { 
  37.    FooClass * p = (FooClass*)object; 
  38.    return p->Foo(arg); 
  39.  } 
  40.  
  41. Of course, the two lines can be combined; I just thought it might 
  42. be clearer when split into two. 
  43. -- 
  44. Pete Grant 
  45. Kalevi, Inc. 
  46. Object Oriented Software Development
  47.